/** UserSession */
package domain.session;

import java.util.ArrayList;
import java.util.List;

import domain.permissions.Permission;

/**
 * Each user has a unique user SESSION
 * @author jessienewman
 * @version $Revision: 1.0 $
 */
public class UserSession {
	/**
	 * Field userId.
	 */
	private Integer userId;
	
	/**
	 * Field SESSIONId.
	 */
	private Integer sessionId; // $codepro.audit.disable variableShouldBeFinal
	
	/**
	 * Field permissions.
	 */
	private List<Permission> permissions;
	//public static UserSession SESSION = new UserSession(-1, -1);
	
	/**
	 * Constructor for UserSession.
	 * @param userId Integer
	 * @param sessionId Integer
	 */
	public UserSession(Integer userId, Integer sessionId) {
		this.userId = userId;
		this.sessionId = sessionId;
		permissions = new ArrayList<Permission>();
	}
	
	/**
	 * Method getUserId.
	
	 * @return Integer */
	public Integer getUserId() {
		return userId;
	}
	
	/**
	 * Method setUserId.
	 * @param id Integer
	 */
	public void setUserId(Integer id) {
		this.userId = id;
	}
	
	/**
	 * Method getSessionId.
	
	 * @return Integer */
	public Integer getSessionId() {
		return sessionId;
	}
	
	/**
	 * Method setPermissions.
	 * @param permissions List<Permission>
	 */
	public void setPermissions(final List<Permission> permissions) {
		this.permissions = permissions;
	}
	
	/**
	 * Method addPermission.
	 * @param permission Permission
	 */
	public void addPermission(final Permission permission) {
		permissions.add(permission);
	}
	
	/**
	 * Method hasPermission.
	 * @param p Permission
	
	 * @return Boolean */
	public Boolean hasPermission(Permission p) {
		return permissions.contains(p);
	}
	
	/**
	 * Method toString.
	
	 * @return String */
	public String toString() {
		return "User Session";
	}
}
